package cn.sheep.violet.utils

import org.apache.spark.sql.Row

/**
  * author: old sheep
  * QQ: 64341393 
  * Created 2018/10/17
  */
object RptKpi {

    def apply(row: Row) ={



        // 提取个指标相关的字段
        val reqMode = row.getAs[Int]("requestmode")
        val proNode = row.getAs[Int]("processnode")
        val effTive = row.getAs[Int]("iseffective")
        val billing = row.getAs[Int]("isbilling")
        val isbid = row.getAs[Int]("isbid")
        val iswin = row.getAs[Int]("iswin")
        val adOrderId = row.getAs[Int]("adorderid")

        val rawReq = if (reqMode == 1 && proNode >= 1) 1 else 0
        val effReq = if (reqMode == 1 && proNode >= 2) 1 else 0
        val adReq = if (reqMode == 1 && proNode == 3) 1 else 0

        val adRtbReq = if (effTive == 1 && billing == 1 && isbid == 1 && adOrderId != 0) 1 else 0
        val adSuccRtbAndCostAndConsumption = if (effTive == 1 && billing == 1 && iswin == 1) {
            val winPrice = row.getAs[Double]("winprice")
            val adPayment = row.getAs[Double]("adpayment")

            (1, adPayment / 1000, winPrice / 1000)

        } else (0, 0d, 0d)

        val adShow = if (reqMode == 2 && effTive == 1) 1 else 0
        val adClick = if (reqMode == 3 && effTive == 1) 1 else 0

        List(rawReq, effReq, adReq, adRtbReq, adSuccRtbAndCostAndConsumption._1, adShow, adClick, adSuccRtbAndCostAndConsumption._2, adSuccRtbAndCostAndConsumption._3)
    }


}
